package cn.touna.jss.modules.custom.carmodel.service;

import cn.touna.jss.common.enums.IntfScopeEnum;
import cn.touna.jss.modules.adapter.ApiMapping;
import cn.touna.jss.modules.custom.carmodel.synctask.Car300SyncModelService;
import cn.touna.jss.modules.custom.carmodel.synctask.CarModelSyncTaskExecutor;
import cn.touna.jss.modules.custom.carmodel.synctask.JzgSyncModelService;
import cn.touna.jss.modules.custom.carmodel.synctask.SyncModelResult;
import cn.touna.jss.modules.third.car300.Car300Service;
import cn.touna.jss.modules.third.jzg.JingZhenGuService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDate;

/**
 * 仅用于测试,不对外开放
 * Created by Steve.Tao on 2017/11/21.
 */
@Service
public class CarModelTestService {

    @Autowired
    private Car300SyncModelService car300SyncModelService;

    @Autowired
    private JzgSyncModelService jzgSyncModelService;

    @Autowired
    private Car300Service car300Service;

    /**
     * 用于测试,不对外开放
     *
     * @return
     */
    @ApiMapping(value = "carmodeltest.refreshModelCar300",scope = IntfScopeEnum.JSS_INTF_TEST)
    public String refreshModelCar300() {
        try {
            SyncModelResult result = car300SyncModelService.refreshModel(LocalDate.now().toString());
            return JSONObject.toJSONString(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 用于测试
     *
     * @return
     */
    @ApiMapping(value = "carmodeltest.refreshModelJzg",scope = IntfScopeEnum.JSS_INTF_TEST)
    public String refreshModelJzg() {
        try {
            SyncModelResult result = jzgSyncModelService.refreshModel(LocalDate.now().toString());
            String res = JSONObject.toJSONString(result);
            System.out.println("-------------------------------------------------------");
            System.out.println(res);
            return res;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "fail";
    }

    @Autowired
    private JingZhenGuService jingZhenGuService;

    /**
     * 用于测试
     *
     * @return
     */
    @ApiMapping(value = "carmodeltest.getJzgMake",scope = IntfScopeEnum.JSS_INTF_TEST)
    public String getJzgMake() throws Exception {
        return jingZhenGuService.getMakeByAll().toJSONString();
    }

    @Autowired
    private CarModelSyncTaskExecutor executor;

    /**
     * 用于测试
     *
     * @return
     */
    @ApiMapping(value = "carmodeltest.saveTaskRecord",scope = IntfScopeEnum.JSS_INTF_TEST)
    public String saveTaskRecord() {
        try {
            executor.test();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Hello";
    }

    @ApiMapping(value = "carmodeltest.getCarModel",scope = IntfScopeEnum.JSS_INTF_TEST)
    public String getCarModel(@RequestParam("seriesId") String seriesId) {
        return car300Service.getCarModelList(seriesId);
    }

}
